#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
using namespace std;
int N; int i, j;
struct Stu
{
	char name[15];
	int chi;
	int math;
	int eng;
	int sum;
}s[1005];
int main()
{
	cin >> N;
	for (i = 0; i < N; i++) {
		scanf("%s%d%d%d", s[i].name, &s[i].chi, &s[i].math, &s[i].eng);
		s[i].sum = s[i].chi + s[i].math + s[i].eng;
	}
	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			if (s[i].chi - s[j].chi <= 5 && s[i].chi - s[j].chi >= -5 &&
				s[i].math - s[j].math <= 5 && s[i].math - s[j].math >= -5 &&
				s[i].eng - s[j].eng <= 5 && s[i].eng - s[j].eng >= -5 &&
				s[i].sum - s[j].sum <= 10 && s[i].sum - s[j].sum >= -10
				) {
				printf("%s %s\n", s[i].name, s[j].name);
			}
		}
	}
	return 0;
}